<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="../js/vue.js"></script>
    <title>基本列表</title>
</head>
<body>
    <!-- 
        v-for指定
            1、用于展示列表数据
            2、语法：v-for=”（item, index）in xxx“ :key="index"
            3、可遍历：数组、对象、字符串（用的少）、指定次数（用的少）
     -->
    <div id="root">
         <!-- 遍历数组 -->
        <h2>人员信息列表（遍历数组）</h2>
        <!-- 写法一 -->
        <!-- <li v-for ="p in persons" :key="p.id"> -->
        <!-- 写法二 in替换为of也可以-->
        <li v-for ="(p, index) in persons" :key="index">
            {{p.name}}-{{p.age}}
        </li>

        <!-- 遍历对象 -->
        <h2>汽车信息列表 （遍历对象）</h2>
        <li v-for="(value, k) in car" :key="k">
            {{k}} -- {{value}}
        </li>

        <!-- 遍历字符串 -->
        <h2>字符串</h2>
        <!-- 下方绑定:key会报错 -->
        <li v-for="(char,index) in str" :key="index">
            {{index}} -- {{char}}
        </li>

        <!-- 遍历指定次数 -->
        <h2>遍历指定次数</h2>
        <li v-for="(number, index) in 5">
            {{index}} -- {{number}}
        </li>
    </div>
    <script type="text/javascript">
        const vm = new Vue({
            el:"#root",
            data(){
                return {
                    persons:[
                        {id:"001", name:"张三", age:"18"},
                        {id:"002", name:"李四", age:"19"},
                        {id:"003", name:"王五", age:"20"}
                    ],
                    car:{
                        name:"BMW x7",
                        price:"100w",
                        color:"黑色"
                    },
                    str:"Aurora"
                }
            }
        })
    </script>
</body>
</html>